/*
 * 入库设备搜索
 * @Author: ljb
 * @Date: 2018-03-27 17:51:07
 * @Last Modified by: ljb
 * @Last Modified time: 2018-10-17 15:23:33
 */
<template>
	<Form
		ref="formInline"
		:model="formValidate"
		name="purchase-search-form"
		inline
		@keydown.native.enter.prevent="confirmSearch">

		<Form-item
			:label-width="isChinese?80:120"
			:label="$t('equipment.code')">
			<i-input
				v-model="formValidate.code"
				:placeholder="$t('equipment.placeholder',{'field':$t('equipment.code')})"
				name="search-code"
				type="text"/>
		</Form-item>

		<Form-item
			:label-width="isChinese?80:120"
			:label="$t('equipment.device_name')">
			<i-input
				v-model="formValidate.device_name"
				:placeholder="$t('equipment.placeholder',{'field':$t('equipment.device_name')})"
				name="search-device_name"
				type="text"/>
		</Form-item>

		<Form-item
			:label-width="isChinese?80:120"
			:label="$t('equipment.specification')">
			<i-input
				v-model="formValidate.specification"
				:placeholder="$t('equipment.placeholder',{'field':$t('equipment.specification')})"
				name="search-specification"
				type="text"/>
		</Form-item>

		<Form-item
			:label-width="isChinese?80:120"
			:label="$t('equipment.producer')">
			<i-input
				v-model="formValidate.producer"
				:placeholder="$t('equipment.placeholder',{'field':$t('equipment.producer')})"
				name="search-producer"
				type="text"/>
		</Form-item>

		<Form-item
			:label-width="isChinese?80:120"
			:label="$t('equipment.buyer')">
			<i-input
				v-model="formValidate.buyer"
				:placeholder="$t('equipment.placeholder',{'field':$t('equipment.buyer')})"
				name="search-buyer"
				type="text"/>
		</Form-item>

		<Form-item
			:label-width="isChinese?80:120"
			:label="$t('equipment.purchase_at')" >
			<DatePicker
				:placeholder="$t('equipment.placeholder',{'field':$t('equipment.purchase_at')})"
				name="search-purchase_at"
				type="daterange"
				placement="bottom-start"
				style="width: 200px"
				@on-change="changeDate"/>
		</Form-item>

		<Form-item>
			<Button
				type="primary"
				@click="confirmSearch">
				{{ $t('common.search') }}
			</Button>
		</Form-item>

	</Form>
</template>
<script>

export default {

	name: 'PurchaseSearchForm',

	props: {
		customers: {
			type: Object,
			default() {
				return {};
			},
		},
	},

	data() {
		return {
			formValidate: {
				code: '',

				uuid: '',

				device_name: '',

				specification: '',

				producer: '',

				buyer: '',

				time_range: [],
			}, // 搜索框的对象参数
		};
	},

	computed: {
		isChinese() {
			return this.$i18n.locale === 'zh-CN';
		},
	},
	methods: {

		/**
		 * 改变日期之后触发的回调
		 * @param  {Array} date {日期区间}
		 * @return {undefined}
		 */
		changeDate(date) {
			this.formValidate.time_range = date;
		},

		/**
		 * 重置参数
		 * @return {undefined}
		 */
		resetParam() {
			this.$refs.formInline.resetFields();
			this.formValidate.time_range = [];
		},

		/**
         * 确认搜索
         * @return {undefined}
         */
		confirmSearch() {
			const param = {
				// uuid: this.formValidate.uuid,

				device_code: this.formValidate.code,

				device_name: this.formValidate.device_name,

				specification: this.formValidate.specification,

				producer: this.formValidate.producer,

				buyer: this.formValidate.buyer,

				time_range: this.formValidate.time_range,
			};

			this.$emit('search', param);
		},

	},

};

</script>
